package com.cn.file.ha;

import com.cn.common.ServerThread;
import io.netty.channel.ChannelHandlerContext;

public class HAConnection {

    private HAService haService;
    private ChannelHandlerContext ctx;
    private WriteServer writeServer;
    private ReadServer readServer;

    public HAConnection(HAService haService, ChannelHandlerContext ctx) {
        this.haService = haService;
        this.ctx = ctx;
        this.writeServer = new WriteServer();
        this.readServer = new ReadServer();

        start();
    }

    public void start() {
        this.writeServer.start();
        this.readServer.start();
    }

    public void shutdown() {
    }

    //写服务
    class WriteServer extends ServerThread {

        @Override
        public String getServiceName() {
            return WriteServer.class.getName();
        }

        @Override
        public void run() {
            System.out.println("向slave端写入数据开始.");
            while (!isStopped()) {
                long offset = haService.getOffset();
                if (offset == -1) {
                    continue;
                }

            }
            System.out.println("向slave端写入数据结束.");
        }
    }

    //读服务
    class ReadServer extends ServerThread {

        @Override
        public String getServiceName() {
            return ReadServer.class.getName();
        }

        @Override
        public void run() {

        }
    }

}
